# ----------------------------------------------------------------------------------------------------------------------
# Replication script for Figure 1 in van Ditmars and Ksiazkiewicz
# "The gender gap in political interest: heritability, gendered political socialization, and the enriched environment hypothesis"
# Politics and the Life Sciences
# ----------------------------------------------------------------------------------------------------------------------

setwd("")

library(tidyverse); library(rio)
dat <- as_tibble(rio::import("figure_1_means.xlsx"))

dat_plot <- dat %>% tidyr::pivot_longer(-key, names_to = "variables", values_to = "values") %>% 
  tidyr::separate(col = variables, into = c("gender", "age"), sep = "_") %>% 
  mutate(gender = factor(gender, labels = c("Female", "Male")), 
         age = factor(age, labels = c("Pre-teens\n(11-12 yrs)", "Teens\n(17-18 yrs)", "Young adults\n(22-25 yrs)")), 
         key = as_factor(key)) %>% 
  tidyr::pivot_wider(names_from = "key", values_from = "values")

p1 <- ggplot(data = dat_plot, aes(x = age, y = interest)) + 
  geom_errorbar(aes(ymin = lb, ymax = ub, group = gender), width = 0.15, position = position_dodge(width=0.3)) + 
  geom_point(aes(fill = gender), shape = 21, color = "black", size = 3, position = position_dodge(width = 0.3)) + 
  theme_bw() + 
  labs(x = "", y = "Interest in politics\n(mean value)") + 
  scale_fill_grey(name = "")

p1

# http://www.evanpickett.com/blog/2016/10/19/r-ggsave-tiff-files-are-too-big
ggsave(filename = "figure_1.tiff", plot = p1, device = "tiff", width = 6, height = 4, dpi = 600, compression = "lzw")
ggsave(filename = "figure_1.png", plot = p1, device = "png", width = 6, height = 4, dpi = 600)